package gamegui;
import gamegui.MainGame.AudioObserver;
import gamegui.MainGame.ButtonTextObserver;
import gamegui.MainGame.Observer;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.CardLayout;
import java.util.ArrayList;

import javax.swing.JComboBox;
import java.awt.Font;
import javax.swing.SwingConstants;
import java.awt.Color;

public class ViewOptions extends JPanel implements Subject{

	/**
	 * Create the panel.
	 */
	final JButton backToMainButton,audioButton,saveButton;
	private String audioChoice;
	final Dimension dim = new Dimension (1100, 730);
	
	private JLabel label_1;
	private JComboBox comboBoxBackground, comboBoxPuck, comboBoxBar;
	
	final Dimension audioSize = new Dimension(165, 60);
	final Point audioLoc;
	Point backgrndLoc;
    Point puckLoc;
    Point barLoc;
    Point saveLoc;
    Point backLoc;
	private ArrayList<Observer> observers = new ArrayList<Observer>();
	private int state;
	private JLabel lblNewLabel;
	private JLabel lblPuckColor;
	private JLabel lblBarColor;
	private JLabel lblBackground;
	private JLabel lblPreferences;
	
	public ViewOptions(String audioChoice) {
		// Variables
		this.audioChoice = audioChoice;
		setPreferredSize(dim);
		
		audioLoc = new Point(385, 365);
        backgrndLoc = new Point(385, 365);
        puckLoc = new Point(550,365);
        barLoc = new Point(650, 365);
        saveLoc = new Point(550, 530);
        backLoc = new Point(15, 600);
        
        // Background initialization
        JLabel label = new JLabel();
        ImageIcon optionsImage = new ImageIcon("screen.jpg");
        setLayout(null);
        label_1 = new JLabel("", optionsImage, JLabel.CENTER);
        label_1.setSize(new Dimension(1129, 749));
        label_1.setLocation(-17, -19);
   
        
        // Back Button 
        backToMainButton = new JButton("Back");
        backToMainButton.setLocation(backLoc);
        backToMainButton.setSize(audioSize);
        label_1.add(backToMainButton);
        
        
        String[] backGroundOptions = {
                "1",
                "2",
                "3",
               
       };
        String[] puckOptions = {
                "Red Puck",
                "Blue Puck",
                "Green Puck",       
       };
        
        String[] userBarOptions = {
                "Red Bar",
                "Blue Bar",
                "Black Bar",
               
       };
        
        comboBoxBar = new JComboBox(userBarOptions);
        label_1.add(comboBoxBar);
        comboBoxBar.setBounds(706, 365, 139, 61);
        comboBoxPuck = new JComboBox(puckOptions);
        label_1.add(comboBoxPuck);
        comboBoxPuck.setBounds(557, 365, 139, 61);
        //  label_1.setPreferredSize(dim);
          
          // Buttons
   	    audioButton = new JButton("off");
   	    label_1.add(audioButton);
   	    audioButton.setSize(new Dimension(165, 60));
   	    audioButton.setLocation(new Point(382, 205));
   	    // Save Button
   	    saveButton = new JButton("Save");
   	    label_1.add(saveButton);
   	    saveButton.setSize(new Dimension(100, 60));
   	    saveButton.setLocation(new Point(515, 494));
   	    add(label_1);
   	    
   	    comboBoxBackground = new JComboBox(backGroundOptions);
   	    label_1.add(comboBoxBackground);
   	    comboBoxBackground.setBounds(373, 365, 163, 60);
   	    comboBoxBackground.setEditable(false);
   	    
   	    lblNewLabel = new JLabel("Audio:");
   	    lblNewLabel.setForeground(new Color(128, 0, 0));
   	    lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
   	    lblNewLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 20));
   	    lblNewLabel.setBounds(251, 206, 100, 30);
   	    label_1.add(lblNewLabel);
   	    
   	    lblPuckColor = new JLabel("Puck Color");
   	    lblPuckColor.setForeground(new Color(128, 0, 0));
   	    lblPuckColor.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 20));
   	    lblPuckColor.setBounds(547, 316, 125, 25);
   	    label_1.add(lblPuckColor);
   	    
   	    lblBarColor = new JLabel("Bar Color");
   	    lblBarColor.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 20));
   	    lblBarColor.setForeground(new Color(128, 0, 0));
   	    lblBarColor.setBounds(690, 315, 120, 25);
   	    label_1.add(lblBarColor);
   	    
   	    lblBackground = new JLabel("Background");
   	    lblBackground.setForeground(new Color(128, 0, 0));
   	    lblBackground.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 20));
   	    lblBackground.setBounds(362, 315, 150, 25);
   	    label_1.add(lblBackground);
   	    
   	    lblPreferences = new JLabel("Preferences");
   	    lblPreferences.setForeground(Color.WHITE);
   	    lblPreferences.setFont(new Font("Tahoma", Font.BOLD, 30));
   	    lblPreferences.setBounds(377, 36, 200, 50);
   	    label_1.add(lblPreferences);
	}
        
	  public int getState() {
	      return state;
	   }

	   public void setState(int state) {
		   this.state = state;
			   
	      notifyAllObservers();
	   }

	   public void attach(Observer observer){
	      observers.add(observer);		
	   }

	   public void notifyAllObservers(){
	      for (Observer observer : observers) {
	         observer.update();
	      }
	   }
//    public JButton initializeAudioButton(String str){
//    	 if(str.equalsIgnoreCase("on")){
//    		this.audioButton = new JButton("on");
//    		System.out.println("on button olusturuldu");
//    	 }
//    	 else{  // if(str.equalsIgnoreCase("off"))
//    		 this.audioButton = new JButton("off");
//    		 System.out.println("off button olusturuldu");
//    	 }
//    	// else  //shouldn't come here actually
//    		// audioButton = new JButton("??");
//         this.audioButton.setSize(audioSize);
//         this.audioButton.setLocation(audioLoc);
//         return this.audioButton;
//    }
	public JButton getBackToMainButton(){
		return backToMainButton;
	}
	public JButton getAudioButton(){
		return this.audioButton;
	}
	public JButton getSavebutton(){
		return this.saveButton;
	}
	public JComboBox getComboBoxBackground(){
		return comboBoxBackground;
	}
	public JComboBox getComboBoxPuck(){
		return comboBoxPuck;
	}
	public JComboBox getComboBoxBar(){
		return comboBoxBar;
	}
	public String getAudioChoice(){
		return audioChoice;
	}
}
